<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>


    <style>
        body {
            padding: 0;
            margin: 0;
            background-color: antiquewhite;


        }

        .box {
            height: 100vh;
            overflow-y: scroll;
            overflow-x: hidden;
            /* 设置滚动吸附类型 
              y:y轴，还可以设置x
              mandatory: 强制吸附
              proximity: 接近吸附,允许中间状态
            */
            /* scroll-snap-type: y mandatory; */
            scroll-snap-type: y proximity;
            scroll-behavior: smooth;

            /* 留出吸附的距离  由此得以排除滚动口被其他内容（如固定定位的工具栏或侧边栏）所遮挡的区域，或在目标元素与滚动口的边之间留出更多余地。*/
            scroll-padding-top: 100px;
            /* scroll-margin-top: 60px; */
        }

        .c {
            width: 100vw;
            height: 100vh;
            background-color: blueviolet;

            /* 
            start:吸附左边
            end:吸附右边
            center:吸附中间
             */
            scroll-snap-align: center;

            /* 每个元素都停留，不然可能一下子滚动多个元素 */
            scroll-snap-stop: always;



        }

        .c:nth-child(2n) {
            background-color: aquamarine;
        }
    </style>
</head>

<body>

    <section class="box">
        <div class="c"></div>
        <div class="c"></div>
        <div class="c"></div>
        <div class="c"></div>
        <div class="c"></div>
    </section>

</body>

</html>